home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / libs / libelf-0.5 / libelf-0 / libelf-0.5.2 / support / elf.h next >
Encoding:
C/C++ Source or Header  |  1995-10-19  |  6.6 KB  |  348 lines

  1. /*
  2. support/elf.h - public header file for systems that lack it.
  3. Copyright (C) 1995 Michael Riepe <riepe@ifwsn4.ifw.uni-hannover.de>
  4.  
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  9.  
  10. This library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. Library General Public License for more details.
  14.  
  15. You should have received a copy of the GNU Library General Public
  16. License along with this library; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19.  
  20. #ifndef _ELF_H
  21. #define _ELF_H
  22.  
  23. #ifdef    __cplusplus
  24. extern "C" {
  25. #endif
  26.  
  27. /*
  28.  * Scalar data types
  29.  */
  30. typedef unsigned long    Elf32_Addr;
  31. typedef unsigned short    Elf32_Half;
  32. typedef unsigned long    Elf32_Off;
  33. typedef long        Elf32_Sword;
  34. typedef unsigned long    Elf32_Word;
  35.  
  36. #define ELF32_FSZ_ADDR    4
  37. #define ELF32_FSZ_HALF    2
  38. #define ELF32_FSZ_OFF    4
  39. #define ELF32_FSZ_SWORD    4
  40. #define ELF32_FSZ_WORD    4
  41.  
  42. /*
  43.  * ELF header
  44.  */
  45. #define EI_NIDENT    16
  46.  
  47. typedef struct {
  48.     unsigned char    e_ident[EI_NIDENT];
  49.     Elf32_Half        e_type;
  50.     Elf32_Half        e_machine;
  51.     Elf32_Word        e_version;
  52.     Elf32_Addr        e_entry;
  53.     Elf32_Off        e_phoff;
  54.     Elf32_Off        e_shoff;
  55.     Elf32_Word        e_flags;
  56.     Elf32_Half        e_ehsize;
  57.     Elf32_Half        e_phentsize;
  58.     Elf32_Half        e_phnum;
  59.     Elf32_Half        e_shentsize;
  60.     Elf32_Half        e_shnum;
  61.     Elf32_Half        e_shstrndx;
  62. } Elf32_Ehdr;
  63.  
  64. /*
  65.  * e-ident
  66.  */
  67. #define EI_MAG0        0
  68. #define EI_MAG1        1
  69. #define EI_MAG2        2
  70. #define EI_MAG3        3
  71. #define EI_CLASS    4
  72. #define EI_DATA        5
  73. #define EI_VERSION    6
  74. #define EI_PAD        7
  75.  
  76. #define ELFMAG0        0x7f
  77. #define ELFMAG1        'E'
  78. #define ELFMAG2        'L'
  79. #define ELFMAG3        'F'
  80. #define ELFMAG        "\177ELF"
  81. #define SELFMAG        4
  82.  
  83. #define ELFCLASSNONE    0
  84. #define ELFCLASS32    1
  85. #define ELFCLASS64    2
  86. #define ELFCLASSNUM    3
  87.  
  88. #define ELFDATANONE    0
  89. #define ELFDATA2LSB    1
  90. #define ELFDATA2MSB    2
  91. #define ELFDATANUM    3
  92.  
  93. /*
  94.  * e_type
  95.  */
  96. #define ET_NONE        0
  97. #define ET_REL        1
  98. #define ET_EXEC        2
  99. #define ET_DYN        3
  100. #define ET_CORE        4
  101. #define ET_NUM        5
  102. #define ET_LOPROC    0xff00
  103. #define ET_HIPROC    0xffff
  104.  
  105. /*
  106.  * e_machine
  107.  */
  108. #define EM_NONE        0
  109. #define EM_M32        1        /* AT&T WE 32100 */
  110. #define EM_SPARC    2        /* SPARC */
  111. #define EM_386        3        /* Intel i386 */
  112. #define EM_68K        4        /* Motorola 68000 */
  113. #define EM_88K        5        /* Motorola 88000 */
  114. #define EM_486        6        /* Intel i486 (do not use this one) */
  115. #define EM_860        7        /* Intel i860 */
  116. #define EM_MIPS        8        /* MIPS R3000 */
  117. #define EM_NUM        9
  118.  
  119. /*
  120.  * e_ident[EI_VERSION], e_version
  121.  */
  122. #define EV_NONE        0
  123. #define EV_CURRENT    1
  124. #define EV_NUM        2
  125.  
  126. /*
  127.  * Section header
  128.  */
  129. typedef struct {
  130.     Elf32_Word        sh_name;
  131.     Elf32_Word        sh_type;
  132.     Elf32_Word        sh_flags;
  133.     Elf32_Addr        sh_addr;
  134.     Elf32_Off        sh_offset;
  135.     Elf32_Word        sh_size;
  136.     Elf32_Word        sh_link;
  137.     Elf32_Word        sh_info;
  138.     Elf32_Word        sh_addralign;
  139.     Elf32_Word        sh_entsize;
  140. } Elf32_Shdr;
  141.  
  142. /*
  143.  * Special section indices
  144.  */
  145. #define SHN_UNDEF    0
  146. #define SHN_LORESERVE    0xff00
  147. #define SHN_LOPROC    0xff00
  148. #define SHN_HIPROC    0xff1f
  149. #define SHN_ABS        0xfff1
  150. #define SHN_COMMON    0xfff2
  151. #define SHN_HIRESERVE    0xffff
  152.  
  153. /*
  154.  * sh_type
  155.  */
  156. #define SHT_NULL    0
  157. #define SHT_PROGBITS    1
  158. #define SHT_SYMTAB    2
  159. #define SHT_STRTAB    3
  160. #define SHT_RELA    4
  161. #define SHT_HASH    5
  162. #define SHT_DYNAMIC    6
  163. #define SHT_NOTE    7
  164. #define SHT_NOBITS    8
  165. #define SHT_REL        9
  166. #define SHT_SHLIB    10
  167. #define SHT_DYNSYM    11
  168. #define SHT_NUM        12
  169. #define SHT_LOPROC    0x70000000
  170. #define SHT_HIPROC    0x7fffffff
  171. #define SHT_LOUSER    0x80000000
  172. #define SHT_HIUSER    0xffffffff
  173.  
  174. /*
  175.  * sh_flags
  176.  */
  177. #define SHF_WRITE    0x1
  178. #define SHF_ALLOC    0x2
  179. #define SHF_EXECINSTR    0x4
  180. #define SHF_MASKPROC    0xf0000000
  181.  
  182. /*
  183.  * Symbol table
  184.  */
  185. typedef struct {
  186.     Elf32_Word        st_name;
  187.     Elf32_Addr        st_value;
  188.     Elf32_Word        st_size;
  189.     unsigned char    st_info;
  190.     unsigned char    st_other;
  191.     Elf32_Half        st_shndx;
  192. } Elf32_Sym;
  193.  
  194. /*
  195.  * Special symbol indices
  196.  */
  197. #define STN_UNDEF    0
  198.  
  199. /*
  200.  * Macros for manipulating st_info
  201.  */
  202. #define ELF32_ST_BIND(i)    ((i)>>4)
  203. #define ELF32_ST_TYPE(i)    ((i)&0xf)
  204. #define ELF32_ST_INFO(b,t)    (((b)<<4)+((t)&0xf))
  205.  
  206. /*
  207.  * Symbol binding
  208.  */
  209. #define STB_LOCAL    0
  210. #define STB_GLOBAL    1
  211. #define STB_WEAK    2
  212. #define STB_NUM        3
  213. #define STB_LOPROC    13
  214. #define STB_HIPROC    15
  215.  
  216. /*
  217.  * Symbol types
  218.  */
  219. #define STT_NOTYPE    0
  220. #define STT_OBJECT    1
  221. #define STT_FUNC    2
  222. #define STT_SECTION    3
  223. #define STT_FILE    4
  224. #define STT_NUM        5
  225. #define STT_LOPROC    13
  226. #define STT_HIPROC    15
  227.  
  228. /*
  229.  * Relocation
  230.  */
  231. typedef struct {
  232.     Elf32_Addr        r_offset;
  233.     Elf32_Word        r_info;
  234. } Elf32_Rel;
  235.  
  236. typedef struct {
  237.     Elf32_Addr        r_offset;
  238.     Elf32_Word        r_info;
  239.     Elf32_Sword        r_addend;
  240. } Elf32_Rela;
  241.  
  242. /*
  243.  * Macros for manipulating r_info
  244.  */
  245. #define ELF32_R_SYM(i)        ((i)>>8)
  246. #define ELF32_R_TYPE(i)        ((unsigned char)(i))
  247. #define ELF32_R_INFO(s,t)    (((s)<<8)+(unsigned char)(t))
  248.  
  249. /*
  250.  * Note entry header
  251.  */
  252. typedef struct {
  253.     Elf32_Word        n_namesz;    /* name size */
  254.     Elf32_Word        n_descsz;    /* descriptor size */
  255.     Elf32_Word        n_type;        /* descriptor type */
  256. } Elf32_Nhdr;
  257.  
  258. /*
  259.  * Well-known descriptor types for ET_CORE files
  260.  */
  261. #define NT_PRSTATUS    1
  262. #define NT_PRFPREG    2
  263. #define NT_PRPSINFO    3
  264.  
  265. /*
  266.  * Program header
  267.  */
  268. typedef struct {
  269.     Elf32_Word        p_type;
  270.     Elf32_Off        p_offset;
  271.     Elf32_Addr        p_vaddr;
  272.     Elf32_Addr        p_paddr;
  273.     Elf32_Word        p_filesz;
  274.     Elf32_Word        p_memsz;
  275.     Elf32_Word        p_flags;
  276.     Elf32_Word        p_align;
  277. } Elf32_Phdr;
  278.  
  279. /*
  280.  * p_type
  281.  */
  282. #define PT_NULL        0
  283. #define PT_LOAD        1
  284. #define PT_DYNAMIC    2
  285. #define PT_INTERP    3
  286. #define PT_NOTE        4
  287. #define PT_SHLIB    5
  288. #define PT_PHDR        6
  289. #define PT_NUM        7
  290. #define PT_LOPROC    0x70000000
  291. #define PT_HIPROC    0x7fffffff
  292.  
  293. /*
  294.  * p_flags
  295.  */
  296. #define PF_R        0x4
  297. #define PF_W        0x2
  298. #define PF_X        0x1
  299. #define PF_MASKPROC    0xf0000000
  300.  
  301. /*
  302.  * Dynamic structure
  303.  */
  304. typedef struct {
  305.     Elf32_Sword        d_tag;
  306.     union {
  307.     Elf32_Word    d_val;
  308.     Elf32_Addr    d_ptr;
  309.     } d_un;
  310. } Elf32_Dyn;
  311.  
  312. /*
  313.  * Dynamic array tags
  314.  */
  315. #define DT_NULL        0
  316. #define DT_NEEDED    1
  317. #define DT_PLTRELSZ    2
  318. #define DT_PLTGOT    3
  319. #define DT_HASH        4
  320. #define DT_STRTAB    5
  321. #define DT_SYMTAB    6
  322. #define DT_RELA        7
  323. #define DT_RELASZ    8
  324. #define DT_RELAENT    9
  325. #define DT_STRSZ    10
  326. #define DT_SYMENT    11
  327. #define DT_INIT        12
  328. #define DT_FINI        13
  329. #define DT_SONAME    14
  330. #define DT_RPATH    15
  331. #define DT_SYMBOLIC    16
  332. #define DT_REL        17
  333. #define DT_RELSZ    18
  334. #define DT_RELENT    19
  335. #define DT_PLTREL    20
  336. #define DT_DEBUG    21
  337. #define DT_TEXTREL    22
  338. #define DT_JMPREL    23
  339. #define DT_NUM        24
  340. #define DT_LOPROC    0x70000000
  341. #define DT_HIPROC    0x7fffffff
  342.  
  343. #ifdef    __cplusplus
  344. }
  345. #endif
  346.  
  347. #endif /* _ELF_H */
  348.